import { allParts } from '../../../pages/product-support/part-funcs';
import { Vector3, Matrix4, Vector3Tuple } from 'three-legacy';

export const transformPointByMatrices = (
  pt: Vector3Tuple | undefined,
  dxid: string,
) => {
  if (!pt) {
    return null;
  }

  const partKey = dxid.split(':')[0];
  const part = allParts.get(partKey);

  const geometryPt = new Vector3().fromArray(pt);

  part?.matrix4Array?.forEach?.((matrix: Matrix4) => {
    geometryPt.applyMatrix4(matrix);
  });

  return geometryPt.toArray();
};
